package im.starchat.chat.activity.profile;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
import butterknife.InjectView;
import im.starchat.chat.R;
import im.starchat.chat.activity.BaseActivity;
import im.starchat.chat.utils.PreferencesStorageUtil;

public class DebugModeActivity extends BaseActivity {

    @InjectView(R.id.debug_back)
    ImageView mback;
    @InjectView(R.id.server_select_radio_group)
    RadioGroup mServerRadioGroup;
    @InjectView(R.id.server_test)
    RadioButton mTestRadioBtn;
    @InjectView(R.id.server_official)
    RadioButton mOfficialRadioBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_debugmode);
        ButterKnife.inject(this);
        mback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if (PreferencesStorageUtil.isUseOfficialUrl(DebugModeActivity.this)) {
            mOfficialRadioBtn.setChecked(true);
        } else {
            mTestRadioBtn.setChecked(true);
        }

        mServerRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.server_test:
                        PreferencesStorageUtil.setUseOfficialUrl(DebugModeActivity.this, false);
                        break;
                    case R.id.server_official:
                        PreferencesStorageUtil.setUseOfficialUrl(DebugModeActivity.this, true);
                        break;
                }
                toast("请退出程序,杀掉进程，重新登陆以便生效", Toast.LENGTH_SHORT);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
